// pages/goods/comment/comment.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var util = require('../../../utils/util');
var common = require('../../../utils/common.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: setting.url,
    comments: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let { goods_id } = options
    this.requestComments(goods_id, 1)
  },

  /** 请求评论数据 */
  requestComments: function (goodsId, commentType) {
    var that = this;
    var requestUrl = that.data.url + '/api/goods/getGoodsComment?goods_id=' + goodsId + '&type=' + commentType;
    request.get(requestUrl, {
      isShowLoading: false,
      success: function (res) {
        var comments = res.data.result;
        for (var i = 0; i < comments.length; i++) {
          comments[i].addTimeFormat = util.formatTime(comments[i].add_time, false);
          comments[i].head_pic = common.getFullUrl(comments[i].head_pic);
        }
        that.setData({ comments: comments });
      }
    });
  },

  /** 预览图片 */
  previewCommentImgs: function (e) {
    let path = e.currentTarget.dataset.item
    wx.previewImage({
      urls: [path]
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})